#include <iostream>
#include <unistd.h>
#include "../../../plcc/thread/Thread.h"
#include "../../../plcc/thread/Mutex.h"
using namespace std;

class MyMtData {
 public:
  MyMtData():t_(0) {}
  void test0() { 
    usleep(1);
    AutoMutex<Mutex>tmp(lock_);
    for(int i=0; i<100; i++){
      t_ *= i;
      cout << "this is a test 0: "<<t_ << endl;
    }
  }
  void test1() { 
    AutoMutex<Mutex>tmp(lock_);
    for(int i=0; i<100; i++){
      cout << "this is a test 1: "<<t_++ << endl;
    }
  }
 private:
  Mutex lock_;
  int    t_;
};
MyMtData d;

class MyThread0 :public Thread {
  virtual void Run() { d.test0(); }
  
};
class MyThread1 :public Thread {
  virtual void Run() { d.test1(); }
  
};

int main () {
  MyThread0 *p1 = new MyThread0;
  MyThread1 *p2 = new MyThread1;
  p1->Start();
  p2->Start();
  p1->Join();
  p2->Join();
  cout << "joined" << endl;
}
